use anyhow::{anyhow, Result};

#[macro_export]
macro_rules! my_try {
    ($expr:expr) => {
        match $expr {
            Ok(v) => v,
            Err(e) => return Err(e),
        }
    };
}

fn main() -> Result<()> {
    let a = my_try!(f1(my_try!(f2(my_try!(f3("a"))))));
    println!("a={}", a);
    let b = my_try!(f3(my_try!(f2(my_try!(f1("b"))))));
    println!("b================={}", b);

    Ok(())
}

fn f1(s: impl AsRef<str>) -> Result<String> {
    let aa = s.as_ref();
    Ok(format!("f1:{}", aa))
}

fn f2(s: impl AsRef<str>) -> Result<String> {
    Ok(format!("f2:{}", s.as_ref()))
}
fn f3(s: impl AsRef<str>) -> Result<String> {
    Err(anyhow!("f3:{}", s.as_ref()))
}
